package ie.dkit.semanticPhotoWeb.server.persistence;

import java.util.Collection;

import ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelation;
import ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO;

import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 * @author Sebastian Ruehl
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
public class PictureRelationDAOHibernateImpl extends HibernateTemplate
		implements PictureRelationDAO {

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#findPictureRelationById(int)
	 */
	public PictureRelation findPictureRelationById(int id) {
		return (PictureRelation) getSession().load(PictureRelation.class, id);
	}
	
	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#getPictureRelations()
	 */
	@SuppressWarnings("unchecked")
	public Collection<PictureRelation> getPictureRelations() {
		return loadAll(PictureRelation.class);
	}

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#save(ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelation)
	 */
	public void save(PictureRelation pictureRelation) {
		saveOrUpdate(pictureRelation);
	}

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#delete(ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelation)
	 */
	public void delete(PictureRelation pictureRelation) {
		super.delete(pictureRelation);
	}

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#getLinkedPictures(int)
	 */
	@SuppressWarnings("unchecked")
	public Collection<PictureRelation> getLinkedPictures(String imageID) {
		return findByNamedQuery("findLinkedPicturesById", imageID);
	}

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#getReferringPictures(int)
	 */
	@SuppressWarnings("unchecked")
	public Collection<PictureRelation> getReferringPictures(String imageID) {
		return findByNamedQuery("findReferringPicturesById",imageID);
	}

	/*
	 * (non-Javadoc)
	 * @see ie.dkit.semanticPhotoWeb.server.persistence.storageObjects.PictureRelationDAO#findARelationsWithContainingPictureID(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	public Collection<PictureRelation> findAllRelationsWithContainingPictureID(String imageID) {
		return findByNamedQuery("findAllRelationsWithContainingPictureID",imageID);
	}

}
